package com.xuebusi.toutiao.admin.api.common.result;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class ApiResult<T> {
    // 请求成功code
    private static final int SUCCESS_CODE = 200;
    // 服务器异常code
    private static final int SERVER_ERR_CODE = 500;
    // 参数错误code
    private static final int PARAMS_ERR_CODE = 400;

    private Integer code;
    private String message;
    private T data;

    public ApiResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResult<T> ok(T data) {
        return new ApiResult(SUCCESS_CODE, "ok", data);
    }

    public static <T> ApiResult<T> error(String message) {
        return new ApiResult(SERVER_ERR_CODE, message, null);
    }

    public static <T> ApiResult<T> error(Integer code, String message) {
        return new ApiResult(code, message, null);
    }
}
